import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;

/**
 * Created by Scott Tiger.
 * User: tomaszsocha
 * Date: 2010-05-05
 * Time: 21:15:08
 */
public class LaczenieZk extends JPanel{
    private ItemZk first;
    private ItemZk second;
    private JButton nowy;
    private JPanel main;
    private JPanel bottom;
    private JFileChooser fc;
    private Polaczenia p;
    private  JComboBox prefyBox;
    private  JComboBox sufyBox;
    public LaczenieZk(final String itemName,Boolean itemOnly,Polaczenia pol){

        this.setLayout(new GridLayout(1,0));
        p = pol;


         main = new JPanel();
         nowy = new JButton();

         prefyBox = new Prefix("Armor");
         sufyBox = new Sufix("Armor");

         this.add(main);

        Action polacz = new AbstractAction("Polacz") {
            public void actionPerformed(ActionEvent actionEvent) {
               String newone = p.polacz((String)first.getSelectedItem(),(String)second.getSelectedItem(),"Armor");
               nowy.setText(newone);
               nowy.setVisible(true);              
/*             first.remove(first.getSelectedIndex());
               second.remove(second.getSelectedIndex());
               first.addItem(newone);
               second.addItem(newone);
               first.setVisible(true);
               second.setVisible(true);*/
            }
        };


        Action next = new AbstractAction("Open") {

          public void actionPerformed(ActionEvent actionEvent) {

             int returnVal = fc.showOpenDialog(LaczenieZk.this);
             if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //This is where a real application would open the file.
                first = new ItemZk(file);
                second = new ItemZk(file);
                 main.add(first);
                 main.add(second);
                 main.add(nowy);
                 nowy.setVisible(false);
                //LaczenieZk.this.add(new ItemZk(file));

            }
          }
        };

        Action czyIstnieje  = new AbstractAction("Open") {

          public void actionPerformed(ActionEvent actionEvent) {
           first = first.czyIstnieja(sufyBox.getSelectedItem().toString(),prefyBox.getSelectedItem().toString());

          }
        };




        JButton open = new JButton(next);
        JButton merge = new JButton(polacz);
        fc = new JFileChooser();

        bottom = new JPanel();
        bottom.add(open);
        bottom.add(merge);
        main.add(prefyBox);
        main.add(sufyBox);
        this.add(bottom);
        


    }
}
